/*
 * Copyright (C) 2011 Wglxy.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.firestorm.eagletrons.dashboard;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;

import com.firestorm.eagletrons.official.R;

/**
 * This is a simple activity that demonstrates the dashboard user interface
 * pattern.
 * 
 */

public class HomeActivity extends DashboardActivity {

	Animation anim_in;
	Animation anim_out;
	Button home_btn1;
	Button home_btn2;
	Button home_btn3;
	Button home_btn4;
	Button home_btn5;
	Button home_btn6;

	/**
	 * onCreate - called when the activity is first created. Called when the
	 * activity is first created. This is where you should do all of your normal
	 * static set up: create views, bind data to lists, etc. This method also
	 * provides you with a Bundle containing the activity's previously frozen
	 * state, if there was one.
	 * 
	 * Always followed by onStart().
	 * 
	 */

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);
		anim_in = AnimationUtils.loadAnimation(this, R.anim.dashboard_fadein);
		anim_out = AnimationUtils.loadAnimation(this, R.anim.dashboard_fadeout);
		home_btn1 = (Button) findViewById(R.id.home_btn_feature1);
		home_btn2 = (Button) findViewById(R.id.home_btn_feature2);
		home_btn3 = (Button) findViewById(R.id.home_btn_feature3);
		home_btn4 = (Button) findViewById(R.id.home_btn_feature4);
		home_btn5 = (Button) findViewById(R.id.home_btn_feature5);
		home_btn6 = (Button) findViewById(R.id.home_btn_feature6);
	}

	/**
	 * onDestroy The final call you receive before your activity is destroyed.
	 * This can happen either because the activity is finishing (someone called
	 * finish() on it, or because the system is temporarily destroying this
	 * instance of the activity to save space. You can distinguish between these
	 * two scenarios with the isFinishing() method.
	 * 
	 */

	protected void onDestroy() {
		super.onDestroy();
	}

	/**
	 * onPause Called when the system is about to start resuming a previous
	 * activity. This is typically used to commit unsaved changes to persistent
	 * data, stop animations and other things that may be consuming CPU, etc.
	 * Implementations of this method must be very quick because the next
	 * activity will not be resumed until this method returns. Followed by
	 * either onResume() if the activity returns back to the front, or onStop()
	 * if it becomes invisible to the user.
	 * 
	 */

	protected void onPause() {
		startAnimation(false);
		super.onPause();
	}

	/**
	 * onRestart Called after your activity has been stopped, prior to it being
	 * started again. Always followed by onStart().
	 * 
	 */

	protected void onRestart() {
		super.onRestart();
	}

	/**
	 * onResume Called when the activity will start interacting with the user.
	 * At this point your activity is at the top of the activity stack, with
	 * user input going to it. Always followed by onPause().
	 * 
	 */

	protected void onResume() {
		super.onResume();
		startAnimation(true);
	}

	public void startAnimation(Boolean resume) {
		if (resume) {
			home_btn1.startAnimation(anim_in);
			home_btn2.startAnimation(anim_in);
			home_btn3.startAnimation(anim_in);
			home_btn4.startAnimation(anim_in);
			home_btn5.startAnimation(anim_in);
			home_btn6.startAnimation(anim_in);
		} else {
			try {
				home_btn1.startAnimation(anim_out);
				home_btn2.startAnimation(anim_out);
				home_btn3.startAnimation(anim_out);
				home_btn4.startAnimation(anim_out);
				home_btn5.startAnimation(anim_out);
				home_btn6.startAnimation(anim_out);
			} catch (Exception e) {

			}
		}
	}

	/**
	 * onStart Called when the activity is becoming visible to the user.
	 * Followed by onResume() if the activity comes to the foreground, or
	 * onStop() if it becomes hidden.
	 * 
	 */

	protected void onStart() {
		super.onStart();
	}

	/**
	 * onStop Called when the activity is no longer visible to the user because
	 * another activity has been resumed and is covering this one. This may
	 * happen either because a new activity is being started, an existing one is
	 * being brought in front of this one, or this one is being destroyed.
	 * 
	 * Followed by either onRestart() if this activity is coming back to
	 * interact with the user, or onDestroy() if this activity is going away.
	 */

	protected void onStop() {
		super.onStop();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu_dashboard, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle item selection
		switch (item.getItemId()) {
		case R.id.menu_dashboard_settings:
			startActivity(new Intent(getApplicationContext(),
					com.firestorm.eagletrons.PreferencesActivity.class));
			return true;
		case R.id.menu_dashboard_exit:
			finish();
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}
} // end class
